package com.jn.erp.web.api.common.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jn.erp.common.core.page.TableDataInfo;
import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.controller.BaseWebAuthController;
import com.jn.erp.security.entity.SysUser;
import com.jn.erp.security.mapper.SysUserMapper;
import com.jn.erp.web.api.common.entity.TLabel;
import com.jn.erp.web.api.common.entity.TLog;
import com.jn.erp.web.api.common.service.TLabelService;
import com.jn.erp.web.api.common.service.TLogService;
import com.jn.erp.web.api.course.entity.TCourseOrder;
import com.jn.erp.web.api.course.entity.TCourseOrderConfig;
import com.jn.erp.web.api.course.service.TCourseOrderConfigService;
import com.jn.erp.web.api.course.service.TCourseOrderService;
import com.jn.erp.web.api.student.entity.Student;
import com.jn.erp.web.api.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyp
 * @since 2024-09-18
 */
@RestController
@RequestMapping("/tLog")
public class TLogController extends BaseWebAuthController {

    @Autowired
    private TLogService tLogService;

    @Autowired
    private SysUserMapper sysUserMapper;
    /**
     修改记录新增新建
     */
    @PostMapping("saveOrderUpdate")
    public AjaxResult saveOrderUpdate(@RequestBody TLog tLog){
        //机构id
        tLog.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tLog.setCreateUser(String.valueOf(getUserId()) );
        tLog.setCreateDate(LocalDateTime.now());
        tLog.setIsDelete("0");
        tLog.setName(sysUserMapper.selectNickByUserId(new SysUser(getUserId(),Long.parseLong(loginDeptAuth()))).getName());
        tLog.setMobile(getLoginUser().getUser().getName());

        String code = tLogService.saveOrderUpdate(tLog);

        return AjaxResult.success(code);
    }





    /**
     列表
     */
    @GetMapping("list")
    public TableDataInfo list( TLog tLog){
        startPage();
        List<TLog> list = tLogService.list(new QueryWrapper<TLog>().eq("org_id",Long.parseLong(loginDeptAuth())).eq("is_delete","0").eq(!Objects.isNull(tLog.getType()),"type",tLog.getType()).eq("order_no",tLog.getOrderNo()));
        return getDataTable(list);
    }


}

